<?php

namespace App\Controller\Api;

use App\Base\BaseController4Api;
use App\Entity\ApiMoney;
use App\Entity\ApiUser;
use App\Model\ApiMoneyConfigModel;
use App\Model\ApiMoneyLogModel;
use App\Model\ApiMoneyModel;
use App\Model\ApiMoneyTypeModel;
use App\Model\ApiUserModel;
use Doctrine\DBAL\Query\QueryBuilder;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;

use Symfony\Component\HttpFoundation\Request;


/**
 * @route("/api")
 */
class ApiMoneyController extends BaseController4Api
{

    /**
     * @route("/money_add",name="ApiMoneyAdd")
     */
    public function add()
    {
        $projectId = $this->getProjectId();
        if (!$uid = $this->getParamRequired("uid")) {return $this->json_out(0,"用户ID缺失");}
        if (!$moneyType = $this->getParamRequired("moneyType")) {return $this->json_out(0,"请选择货币类型");}
        if (!$money = $this->getParamRequired("money")) {return $this->json_out(0,"请输入金额");}
        if (!$code = $this->getParamRequired("code")) {return $this->json_out(0,"请输入变动类型代码");}
        if (!$tips = $this->getParamRequired("tips")) {$tips = "";}
        $ApiMoneyLogModel = new ApiMoneyLogModel($this->getDoctrine());
        $rst = $ApiMoneyLogModel->add($projectId,$uid,$moneyType,$code,$money,$tips);
        if ($rst) {
            //产生了错误
            return $this->json_out(0,"error",$rst);
        }else{
            return $this->json_out(1,"添加成功","");
        }
    }


    /**
     * @route("/get_user_money",name="ApiGetUserMoney")
     */
    public function ApiGetUserMoney()
    {
        $projectId = $this->getProjectId();
        if (!$uid = $this->getParamRequired("uid")) {return $this->json_out(0,"用户ID缺失");}
        $ApiMoneyModel = new ApiMoneyModel($this->getDoctrine());
        $data = $ApiMoneyModel->getMoneyProject($projectId, $uid);
        return $this->json_out(1,"OK",$data);
    }


    /**
     * @route("/money_add_static",name="ApiMoneyAddStatic")
     */
    public function ApiMoneyAddStatic()
    {
        $projectId = $this->getProjectId();
        if (!$uid = $this->getParamRequired("uid")) {return $this->json_out(0,"用户ID缺失");}
        if (!$moneyType = $this->getParamRequired("moneyType")) {return $this->json_out(0,"请选择货币类型");}
        if (!$money = $this->getParamRequired("money")) {return $this->json_out(0,"请输入金额");}
        if (!$code = $this->getParamRequired("code")) {return $this->json_out(0,"请输入变动类型代码");}
        if (!$tips = $this->getParamRequired("tips")) {$tips = "";}
        $ApiMoneyLogModel = new ApiMoneyLogModel($this->getDoctrine());
        $rst = $ApiMoneyLogModel->add($projectId,$uid,$moneyType,$code,$money,$tips);
        if ($rst) {
            //产生了错误
            return $this->json_out(0,"error",$rst);
        }else{
            return $this->json_out(1,"添加成功","");
        }
    }
}
